from apps.common.base.serializers import *
from apps.merchant.shop.models import *


class ShopBaseSerializer(BaseSerializer):
    class Meta:
        model = Shop
        fields = "__all__"


class ShopModelSerializer(BaseSerializer):

    userModel = serializers.SerializerMethodField()
    def get_userModel(self, obj):
        try:
            return {'id': obj.user.id, 'code': obj.user.code, 'phone': obj.user.phone}
        except:
            return {}
        
    tradeModel = serializers.SerializerMethodField()
    def get_tradeModel(self, obj):
        try:
            return {'id': obj.trade.id, 'name': obj.trade.name}
        except:
            return {}
        
    checkStatusLabel = serializers.SerializerMethodField()
    def get_checkStatusLabel(self, obj):
        if obj.checkStatus:
            return obj.get_checkStatus_display()
        else:
            return '未知'

    class Meta:
        model = Shop
        fields = "__all__"
